<template>
  <div>
    <QueryForm
      v-model="filters"
      :query-form-config="queryFormConfig"
      @handleQuery="getList(1)"
      @clear="clear"
    />
    <el-table
      ref="table"
      v-loading="listLoading"
      :data="list"
      element-loading-text="Loading"
      border
      fit
      :header-row-class-name="'table-header'"
      class="doumee-element-table doumee-element-tableb"
    >
      <el-table-column
        align="center"
        :label="translate('withdrawNum')"
        prop="id"
        show-overflow-tooltip
        min-width="280"
      />
      <el-table-column
        :label="translate('memberInfo')"
        min-width="250"
        align="center"
        show-overflow-tooltip
      >
        <template slot-scope="scope">
          {{ scope.row.nickName || "" }}
          {{ scope.row.phone || scope.row.memberCard ? "-" : ""
          }}{{ scope.row.phone || ""
          }}{{ scope.row.phone && scope.row.memberCard ? "-" : ""
          }}{{ scope.row.memberCard || "" }}
        </template>
      </el-table-column>
      <el-table-column
        align="center"
        :label="translate('withdrawJe')"
        prop="amount"
        min-width="90"
        show-overflow-tooltip
      />
      <el-table-column
        align="center"
        :label="translate('withdrawZsje')"
        prop="giveAmount"
        min-width="110"
        show-overflow-tooltip
      />
      <el-table-column
        :label="translate('withdrawFs')"
        prop="wayType"
        min-width="90"
        align="center"
      >
        <template slot-scope="scope">
          {{
            scope.row.wayType == 0
              ? translate("wx")
              : scope.row.wayType == 1
                ? translate("zfb")
                : scope.row.wayType == 2
                  ? translate("xj")
                  : ""
          }}
        </template>
      </el-table-column>
      <el-table-column
        align="center"
        :label="translate('handleTime')"
        prop="createTime"
        show-overflow-tooltip
        min-width="160"
      />
      <el-table-column
        align="center"
        :label="translate('operator')"
        prop="creatorName"
        show-overflow-tooltip
        min-width="120"
      />
      <el-table-column
        align="center"
        :label="translate('fkcgsj')"
        prop="payTime"
        show-overflow-tooltip
        min-width="160"
      />
      <el-table-column
        align="center"
        :label="translate('errCode')"
        prop="code"
        min-width="260"
        show-overflow-tooltip
      />
      <el-table-column
        align="center"
        :label="translate('errCause')"
        prop="msg"
        show-overflow-tooltip
        min-width="140"
      />
      <el-table-column
        :label="translate('bz')"
        show-overflow-tooltip
        prop="note"
        min-width="120"
        align="center"
      />
      <el-table-column
        :label="translate('status')"
        prop="status"
        min-width="100"
        align="center"
        fixed="right"
      >
        <template slot-scope="scope">
          {{
            scope.row.status == 0
              ? translate('chuliz')
              : scope.row.status == 1
                ? translate('success')
                : scope.row.status == 2
                  ? translate('error')
                  : ""
          }}
        </template>
      </el-table-column>
      <el-table-column
        :label="translate('handle')"
        min-width="140"
        align="center"
        fixed="right"
      >
        <template slot-scope="scope">
          <div class="flex-cc">
            <el-button
              v-if="
                scope.row.status == 0 &&
                  meta.indexOf('MemberWithdrawalOperation') > -1
              "
              v-preventReClick
              type="text"
              @click="updateStatus(scope.row.id, 0)"
            >{{ translate("refundPrice") }}</el-button>
            <el-button
              v-if="
                scope.row.status == 0 &&
                  meta.indexOf('MemberWithdrawalOperation') > -1
              "
              v-preventReClick
              type="text"
              @click="updateStatus(scope.row.id, 1)"
            >{{ translate("success") }}</el-button>
            <div v-if="scope.row.status != 0">-</div>
          </div>
        </template>
      </el-table-column>
    </el-table>
    <!-- <div class="flex-cc doumee-pagination">
      <el-pagination
        hide-on-single-page
        background
        layout="prev, pager, next"
        :current-page.sync="pagination.page"
        :total="total"
        @current-change="getList"
      />
    </div> -->
    <Paginations
      :total="total"
      :page="pagination.page"
      @current-change="getList"
      @SizeChange="handleSizeChange"
    />
  </div>
</template>

<script>
import { memberWithdrawalRecord, memberWithdrawalFailed } from '@/api'
import { parseTime } from '@/utils/index'
import QueryForm from '@/components/QueryForm'
import { queryFormConfig } from './config'
export default {
  name: 'WithDrawRecord',
  components: {
    QueryForm
  },
  data() {
    return {
      queryFormConfig,
      list: [],
      meta: [],
      listLoading: true,
      pagination: {
        page: 1,
        rows: 10,
        firstQueryTime: ''
      },
      total: 0,
      filters: {}
    }
  },
  created() {
    this.meta = this.$route.meta.buttons || []
    this.getList(1)
  },
  mounted() {
    this.$refs.table.doLayout()
  },
  methods: {
    handleSizeChange(value) {
      this.pagination.rows = value
      this.getList(1)
    },
    // 获取列表
    getList(page) {
      const { pagination, filters } = this
      if (page) {
        pagination.page = page
        this.pagination.page = page
      }
      pagination.firstQueryTime = parseTime(new Date())
      this.listLoading = true
      memberWithdrawalRecord({
        pagination,
        param: {
          venueId: sessionStorage.getItem('venueId'),
          startTime: filters.time && filters.time.length > 0 ? filters.time[0] : null,
          endTime: filters.time && filters.time.length > 0 ? filters.time[1] : null,
          ...filters
        }
      })
        .then((res) => {
          this.listLoading = false
          if (res.errorCode !== '000000') return
          this.list = res.recordList
          this.total = res.totalCount
        })
        .catch(() => {
          this.listLoading = false
        })
    },
    toDetail(id) {
      // console.log(id)
      this.$router.push({
        name: 'NoticeDetail',
        query: {
          id
        }
      })
    },
    // 清空
    clear() {
      this.filters = {}
      this.getList(1)
    },
    updateStatus(id, status) {
      let str = ''
      if (status === 1) {
        str = this.translate('qrcga')
      } else {
        str = this.translate('qrtka')
      }
      this.$confirm(str, this.translate('ts'), {
        confirmButtonText: this.translate('qd'),
        cancelButtonText: this.translate('cancel'),
        type: 'warning'
      }).then(() => {
        memberWithdrawalFailed({ param: { id, status }})
          .then(res => {
            if (res.errorCode === '000000') {
              if (status === 1) {
                this.$message.success(this.translate('handleScs'))
              } else {
                this.$message.success(this.translate('useStatus8'))
              }
              this.getList()
            }
          })
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.vip-info {
  display: flex;
  justify-content: center;
  .name-phone {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    text-align: left;
    margin-left: 10px;
  }
}
.viplist-entitycard-style {
  width: 50%;
}
.viplist-btn-style {
  margin-left: 20px;
}
.tableClass .cell {
  padding: 0 !important;
  height: 40px;
  line-height: 30px !important;
  text-align: center;
}
</style>
